package com.shijie.newvideo;

import android.content.Context;
import android.view.View;

import com.shijie.newvideo.base.BaseRecyclerViewAdapter;
import com.shijie.newvideo.base.BaseRecyclerViewHolder;
import com.shijie.newvideo.databinding.ItemVodDetailJishuBinding;

import java.util.List;

public class VodDetailListAdapter extends BaseRecyclerViewAdapter<IdNameBean> {
    private int selectIndex = 0;

    public VodDetailListAdapter(Context context, List<IdNameBean> data) {
        super(context, data);
    }

    @Override
    protected BaseRecyclerViewHolder<IdNameBean> createViewHolder(View itemView) {
        return new ViewHolder(ItemVodDetailJishuBinding.bind(itemView));
    }

    @Override
    protected int getItemLayoutRes(int viewType) {
        return R.layout.item_vod_detail_jishu;
    }

    class ViewHolder extends BaseRecyclerViewHolder<IdNameBean> {

        private final ItemVodDetailJishuBinding binding;

        public ViewHolder(ItemVodDetailJishuBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

        @Override
        public void bindTo(final IdNameBean bean, final int position) {
            super.bindTo(bean, position);
            if (selectIndex == position) {
                binding.tvName.setBackgroundResource(R.drawable.shape_famous_investor_select);
            } else {
                binding.tvName.setBackgroundResource(R.drawable.shape_famous_investor_nomal);
            }
            binding.tvName.setText(bean.getId());
            setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(View itemView, int position) {
                    if (mListener != null) {
                        mListener.shareFlashOnClick(bean);
                        selectIndex = position;
                        notifyDataSetChanged();
                    }
                }
            });
        }
    }


    public ShareOnClickListener mListener;

    public interface ShareOnClickListener {
        void shareFlashOnClick(IdNameBean idNameBean);
    }

    public void setShareOnClickListener(ShareOnClickListener mListener) {
        this.mListener = mListener;
    }
}
